package com.gxuwz.controller;

import com.gxuwz.mapper.InstructorMapper;
import com.gxuwz.mapper.StudentMapper;
import com.gxuwz.mapper.UserMapper;
import com.gxuwz.model.entity.Instructor;
import com.gxuwz.model.entity.Student;
import com.gxuwz.model.entity.User;
import com.gxuwz.model.vo.Result;
import com.gxuwz.model.vo.UserVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;


@RestController
@RequestMapping("/api")
@CrossOrigin
public class LoginContorller {
    @Autowired
    StudentMapper studentMapper;
    @Autowired
    UserMapper userMapper;
    @Autowired
    InstructorMapper instructorMapper;
    @ResponseBody
    @PostMapping("/Student_login")
    public Result Student_login(@RequestBody UserVo userVo) {
        System.out.println("登录");
        Student student = studentMapper.selectUserByStuID(userVo.getId());
        if (student == null) {
            return Result.error("登陆成功");
        }
        if (userVo.getPassword().equals(student.getPassword())) {
            System.out.println("登陆成功");
            return Result.succeed();

        }
        return Result.error("登录失败");
    }
    @ResponseBody
    @PostMapping ("/User_login")
    public Result User_login(@RequestBody UserVo userVo){
        User user = userMapper.selectUserByUserID(userVo.getId());
        if(user == null){
            return Result.error("登录失败");
       }
        if(userVo.getPassword().equals(user.getPassword())){
            return Result.succeed(user);
        }
        return Result.error("登录失败");
    }
    @ResponseBody
    @PostMapping("/Instructor_login")
    public Result Instructor_Login(@RequestBody UserVo userVo) {
        Instructor instructor = instructorMapper.selectInstByInstId(userVo.getId());
        if (instructor == null) {
            return Result.error("登录失败");
        }
        if (userVo.getPassword().equals(instructor.getPassword())) {
            return Result.succeed(instructor);
        }
        return Result.error("登录失败");
    }

}
